package interview.alibaba;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author <a href="zhaoyingling12@163.com">Zhao Simon</a>
 * @program: arithmetic-learning
 * @description: 去重
 * @since
 */
public class FillterObject {

    public static void main(String[] args) {
        Student student1 = new Student("1001", "张一");
        Student student2 = new Student("1002", "张二");
        Student student3 = new Student("1003", "张三");
        Student student4 = new Student("1004", "张四");
        Student student5 = new Student("1003", "张三");
        Student student6 = new Student("1004", "张四");

        List<Student> list = new ArrayList<>();
        list.add(student1);
        list.add(student2);
        list.add(student3);
        list.add(student4);
        list.add(student5);
        list.add(student6);

        Set<Student> set = new HashSet<>();
        List<Student> filterList = list.stream().
                filter(student -> {
                    if (set.contains(student)) {
                        return false;
                    } else {
                        set.add(student);
                        return true;
                    }
                }).collect(Collectors.toList());

        filterList.forEach(student -> System.out.println("student ==> " + student));
    }
}
